import type { App } from 'vue';
import mitt from 'mitt';
import './utils/const.js';
import './utils/formhelper.js';
import './style/index.css';
import { $tra } from '@/utils/index.js';
import LbTable from './packages/lb-table/index.js';
import TableFilter from './packages/table-filter/index.js';
import TableOperate from './packages/table-operate/index.js';
import eleDisTypes from './packages/table-filter/src/components/index.js';
import CommonDialog from './packages/common-dialog/index.js';
import CustomTab from './packages/custom-tab/index.js';
import dialog from './plugins/dialog.js';
import ComplexForm from './packages/complex-form/index.js'
import ComplexForm2 from './packages/custom-form/src/complex.vue'
import CommonPage from './views/Core/common-page/index.vue'
import inputFilter from './utils/directives.js'
window.zoom = 1

const components = [TableOperate, LbTable, TableFilter, CommonDialog, CustomTab, ComplexForm, CommonPage];

import {
  $timeFormate,
  $$confirm,
  $$message,
  $$success
} from './utils/prototype'
import {
  download,
  getDownload
} from './utils/download.js'


export default {
  install(app: App) {
    // Vue3 事件总线
    const eventBus = mitt();
    app.config.globalProperties.$bus = eventBus;

    app.config.globalProperties.$tra = $tra;
    app.config.globalProperties.$timeFormate = $timeFormate;
    app.config.globalProperties.$$confirm = $$confirm;
    app.config.globalProperties.$$message = $$message;
    app.config.globalProperties.$$success = $$success;
    app.config.globalProperties.$download = download;
    app.config.globalProperties.$getDownload = getDownload;
    app.directive('input-filter', inputFilter);
    // 设置 dialog 插件的应用实例
    dialog.setAppInstance(app);

    components.forEach(component => {
      // 注册组件
      app.component(component.name, component);
    });

    Object.keys(eleDisTypes).forEach(eleDisTypeName => {
      app.component(eleDisTypes[eleDisTypeName].name, eleDisTypes[eleDisTypeName]);
    });
    app.component('ComplexForm2', ComplexForm2);
  }
};
